define(['jquery', 'bootstrap', 'userend', 'table', 'form'], function ($, undefined, Userend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'mall/order/complain/index',
                    detail_url: 'mall/order/complain/detail',
                    multi_url:'mall/order/complain/multi',
                    table: 'mall_order_complain',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('ID')},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'complain_target_id_text', title: __('Complaintargetid')},
                        {field: 'complainType', title: __('Complaintype'), searchList: {"1":__('Complaintype 1'),"2":__('Complaintype 2'),"3":__('Complaintype 3'),"4":__('Complaintype 4')}, formatter: Table.api.formatter.normal},
                        {field: 'respondTargetId', title: __('Respondtargetid'), visible:false},
                        {field: 'complainimgs', title: __('Complainimgs'), formatter: Table.api.formatter.images},
                        {field: 'needRespond', title: __('Needrespond'), formatter:Table.api.formatter.toggle},
                        {field: 'deliverRespondTime', title: __('Deliverrespondtime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'complainStatus', title: __('Complainstatus'), searchList: {"0":__('Complainstatus 0'),"1":__('Complainstatus 1'),"2":__('Complainstatus 2'),"3":__('Complainstatus 3'),"4":__('Complainstatus 4')}, formatter: Table.api.formatter.status},
                        {field: 'complainTime', title: __('Complaintime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'respondimgs', title: __('Respondimgs'), formatter: Table.api.formatter.images},
                        {field: 'respondTime', title: __('Respondtime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'finalResultTime', title: __('Finalresulttime'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons:[{
                                name: 'detail',
                                text: __("Detail"),
                                classname: 'btn btn-xs btn-success btn-dialog',
                                icon: 'fa fa-eye',
                                url: 'mall/order/complain/detail'
                            },{
                                name: 'edit2',
                                text: __("Edit"),
                                classname: 'btn btn-xs btn-success btn-dialog',
                                icon: 'fa fa-pencil',
                                url: 'mall/order/complain/edit',
                                visible: function (row){
                                    return row.complainStatus<2;
                                }
                            }],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        detail: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});